//
//  UILabelMultiLineViewController.m
//  iOS UI Sample Code
//
//  Created by 규성 이 on 12. 2. 20..
//  Copyright (c) 2012년 kkamci77@gmail.com. All rights reserved.
//

#import "UILabelMultiLineViewController.h"

@implementation UILabelMultiLineViewController

@synthesize lblFirst, lblSecond, lblThird;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self.navigationItem setTitle:@"MultiLine"];
    NSString * str = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ-ABCDEFGHIJKLMNOPQRSTUVWXYZ-ABCDEFGHIJKLMNOPQRSTUVWXYZ-ABCDEFGHIJKLMNOPQRSTUVWXYZ-ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    [self.lblFirst setText:str];
    [self.lblSecond setText:str];
    [self.lblThird setText:str];
    
    [self.lblFirst setBackgroundColor:UIColor.blackColor];
    [self.lblFirst setTextColor:UIColor.whiteColor];
    [self.lblSecond setBackgroundColor:UIColor.redColor];
    [self.lblThird setBackgroundColor:UIColor.blueColor];
    
//    [self.lblFirst setNumberOfLines:1];
    [self.lblSecond setNumberOfLines:2];
    [self.lblThird setNumberOfLines:3];

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)dealloc {
    [lblFirst release];
    [lblSecond release];
    [lblThird release];
    
    [super dealloc];
}

-(IBAction)sizeToFitAction:(id)sender
{
    [self.lblFirst sizeToFit];
    [self.lblSecond sizeToFit];
    [self.lblThird sizeToFit];
}

-(IBAction)sizeToThatAction:(id)sender
{
    NSString * test = @"abcde한글";
    [self.lblFirst setText:[NSString stringWithFormat:@"%d, %d",[test lengthOfBytesUsingEncoding:NSUTF16LittleEndianStringEncoding], [test length]]];
//    CGSize firstSize = [self.lblFirst.text sizeWithFont:self.lblFirst.font constrainedToSize:CGSizeMake(320.0f, 400.0f) lineBreakMode:UILineBreakModeTailTruncation];
//    [self.lblFirst sizeThatFits:firstSize];
//    firstSize = [self.lblFirst.text sizeWithFont:self.lblFirst.font constrainedToSize:self.lblFirst.frame.size lineBreakMode:UILineBreakModeTailTruncation];
    
//    self.lblFirst sizeThatFits:CGSizeMake(320.0f, );
}
@end
